package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.inject.internal.cglib.core.$ObjectSwitchCallback;
import com.ssps.back.platform.service.LogService;
import com.ssps.entity.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/24 16:42:05
 */

@Controller
@RequestMapping("log")
public class LogController {

    @Autowired
    LogService logService;

    @RequestMapping("logList")
    public String logList(){
        return "/log/logList";
    }

    @ResponseBody
    @RequestMapping("findAll")
    public Map<String, Object> LogFindAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize , String uname){
        Map<String,Object> map=new HashMap<>();

        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Log> logList=logService.logfindAll(uname);
            PageInfo<Log>pageInfo=new PageInfo<>(logList);
            map.put("pageInfo",pageInfo);
            map.put("logList",logList);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",true);
            e.printStackTrace();
        }
        return map;
    }

}
